<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php的查询</title>
</head>
<body>
<?php

if(isset($_POST['username'])&&isset($_POST['password'])){
    $username=$_POST['username'];
    $password=$_POST['password'];
}


if(isset($_GET["p"]))//是否存在"id"的参数
{
    $pageNum = $_GET['p'];//存在
}else{
    $pageNum =1;
}
/*}*/

//每页显示条数
$pageSize = 3;

//根据pageSize和pageNum计算从第几条开始查询
$pageStart = ($pageNum-1)*$pageSize;

//从系统服务器获取当前的页码
/*$currentPage = $_SERVER;

echo "<pre>";
print_r($currentPage);*/

$pagePre = $pageNum-1;
$pageNext =$pageNum+1;

header("Content-Type:text/html; charset=utf-8");
//连接数据库
$conn=mysql_connect('localhost:3306','root','root') or die("连接数据库失败");
$db=mysql_select_db("test");
$query="select * from php_user order by id limit $pageStart,$pageSize  ";

$result=mysql_query($query);
mysql_query('SET NAMES utf-8');
$data=mysql_fetch_array($result);

$total =mysql_fetch_array(mysql_query("select count(*) from php_user"));
$totalNum = ceil($total[0]/$pageSize);


if(mysql_num_rows($result)>0){
	?>
<br/>


<div>
    欢迎您！<?php
    if(isset($username)){
        echo $username;
    }

    ?> </br>
    密码：<?php
    if(isset($password)) {
        echo $password;
    }
    ?> </br>
</div>

<div>
    http get请求模拟：
    <?php
    $url='http://ajj.fuwo.com/AJJ/jsp/noticeAJJRenderResult.action';
    $html = file_get_contents($url);
    echo $html;
    ?>
  <br/>  http post请求模拟：
    <?php
        $data = array ('data' => '11111');
        $data = http_build_query($data);

        $opts = array (
            'http' => array (
            'method' => 'POST',
            'header'=> "Content-type: application/x-www-form-urlencodedrn".
            "Content-Length: " . strlen($data) . "rn",
            'content' => $data
            )
        );

        $context = stream_context_create($opts);
        $html = file_get_contents('http://ajj.fuwo.com/AJJ/jsp/noticeAJJRenderResult.action', false, $context);
        echo $html;
    ?>

</div>




<div style="text-align: center">PHP单表增删改查demo</div>
<hr/>
<table border="1" align="center" background="#99CCFFLL">
	<tr>
		<td align="center">ID</td>
		<td align="center">username</td>
		<td align="center">address</td>
		<td align="center">tel</td>
		<td align="center">content</td>
		<td align="center">dowork</td>
	</tr>
    <?php
    do {
        echo "<tr>";
        echo "<td>$data[id]</td>";
        echo "<td>$data[username]</td>";
        echo "<td>$data[address]</td>";
        echo "<td>$data[tel]</td>";
        echo "<td>$data[content]</td>";
        echo "<td><a href='add.html'>添加用户</a>
				 <a href='del.php?uid=$data[id]'>删除用户</a>
				 <a href='update.html?id=$data[id]&username=$data[username]&address=$data[address]&tel=$data[tel]&content=$data[content]'>修改用户</a></td>";
        echo "</tr>";
    }
    while ($data=mysql_fetch_array($result));

    echo " <tr><td colspan='6' align='center'>
         <a  href='index.php?p=1'>首页</a>
         <a href='index.php?p=$pagePre'>上一页</a> <a href='index.php?p=$pageNext'>下一页</a>
         <a  href='index.php?p=$totalNum'>尾页</a>
         <span>第{$pageNum}页，总条数：{$total[0]}条，共{$totalNum}页，跳转至<input name='p'/>页<input type='submit'  value='确定'/></span>
         </td></tr>";
    }
    else
    {
        echo "没有数据";
    } ?>
</table>
</body>
</html>
